import { Injectable } from '@angular/core';
import { ApolloQueryResult, FetchResult } from '@apollo/client/core';
import { Apollo, gql, QueryRef } from 'apollo-angular';
import { Observable } from 'rxjs';
import { AdministratorServiceApi,
AdministratorService_listResult,
AdministratorService_listVariables,
AdministratorService_totalCountResult,
AdministratorService_searchResult,
AdministratorService_searchVariables,
AdministratorService_loadAllResult,
AdministratorService_getByIdResult,
AdministratorService_getByIdVariables,
AdministratorService_createAdminResult,
AdministratorService_createAdminVariables,
AdministratorService_saveResult,
AdministratorService_saveVariables,
AdministratorService_removeByIdResult,
AdministratorService_removeByIdVariables,
AdministratorService_removeByIdListResult,
AdministratorService_removeByIdListVariables,
AdministratorResultInfo, AdministratorPageInfo,
AdministratorConnection,
AdministratorPackage,
AdministratorOrderBy,
AdministratorMutationInfo,
AdministratorStringFilter,
AdministratorNumberFilter,
AdministratorBooleanFilter,
administratorServiceQuery,
administratorServiceMutation,
AdministratorServiceQueryOptions,
AdministratorStore,
AdministratorView,
AdministratorInput,
AdministratorFilter,
AdministratorErrorBody} from '../model/administrator_service.model';

/************************************************************************
 * 管理员管理
 */
@Injectable({
    providedIn: 'root'
})
export class AdministratorService implements AdministratorServiceApi {

        private listGql:string;
        private totalCountGql:string;
        private searchGql:string;
        private searchObjectRef: QueryRef<AdministratorService_searchResult>;
        private loadAllGql:string;
        private getByIdGql:string;

    constructor(private apollo: Apollo) {
        this.listGql=`query aap_administratorService_list($filter: AdministratorFilter!,$orderBy: OrderBy){${administratorServiceQuery.administratorService_list}}`;
        this.totalCountGql=`query aap_administratorService_totalCount{${administratorServiceQuery.administratorService_totalCount}}`;
        this.searchGql=`query aap_administratorService_search($first: Int!,$offset: Float!,$filter: AdministratorFilter!,$orderBy: OrderBy){${administratorServiceQuery.administratorService_search}}`;
        this.searchObjectRef = apollo.watchQuery<AdministratorService_searchResult>({ query: gql`${this.searchGql}`, fetchPolicy:'cache-first' });
        this.loadAllGql=`query aap_administratorService_loadAll{${administratorServiceQuery.administratorService_loadAll}}`;
        this.getByIdGql=`query aap_administratorService_getById($id: String!){${administratorServiceQuery.administratorService_getById}}`;
    }
    /**
     * 分页查询
     */
    list(variables: AdministratorService_listVariables, options:AdministratorServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<AdministratorService_listResult>> {
            return this.apollo.query({ query: gql`${this.listGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 统计库中所有对象的数据量
     */
    totalCount(options:AdministratorServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<AdministratorService_totalCountResult>> {
            return this.apollo.query({ query: gql`${this.totalCountGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 游标查询
     */
    search(variables: AdministratorService_searchVariables, options:AdministratorServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AdministratorService_searchResult>> {
        this.searchObjectRef.setVariables(variables);
        if(options.more){
            this.searchObjectRef.fetchMore({variables});
        }
        return this.searchObjectRef.valueChanges;
    }
    /**
     * 获取库中所有数据，数据量大时请谨慎使用
     */
    loadAll(options:AdministratorServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AdministratorService_loadAllResult>> {
            return this.apollo.query({ query: gql`${this.loadAllGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 获取一个对象
     */
    getById(variables: AdministratorService_getByIdVariables, options:AdministratorServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AdministratorService_getByIdResult>> {
            return this.apollo.query({ query: gql`${this.getByIdGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 创建管理员
     */
    createAdmin(variables: AdministratorService_createAdminVariables): Observable<FetchResult<AdministratorService_createAdminResult>>{
        return this.apollo.mutate({mutation: gql`mutation aap_administratorService_createAdmin($administrator: AdministratorInput!,$password: String!){${administratorServiceMutation.administratorService_createAdmin}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 保存对象
     */
    save(variables: AdministratorService_saveVariables): Observable<FetchResult<AdministratorService_saveResult>>{
        return this.apollo.mutate({mutation: gql`mutation aap_administratorService_save($entity: AdministratorInput!){${administratorServiceMutation.administratorService_save}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一个对象
     */
    removeById(variables: AdministratorService_removeByIdVariables): Observable<FetchResult<AdministratorService_removeByIdResult>>{
        return this.apollo.mutate({mutation: gql`mutation aap_administratorService_removeById($id: String!){${administratorServiceMutation.administratorService_removeById}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一批对象
     */
    removeByIdList(variables: AdministratorService_removeByIdListVariables): Observable<FetchResult<AdministratorService_removeByIdListResult>>{
        return this.apollo.mutate({mutation: gql`mutation aap_administratorService_removeByIdList($ids: [String]!){${administratorServiceMutation.administratorService_removeByIdList}}`, variables,fetchPolicy:'no-cache'});
    }









}
